const mssql = require("mssql");
const config = require("./MSSQLConfig.js");

/**
 *@module database connection
 *@name MssqlDBConn
 *@desc SQL Server数据库连接类
 *@author LiHongKun
 *@date 2018-10-19 11:06:05
 */
async function getQuery(sql){
    return new Promise(function (resolve, reject) {
        const pool = new mssql.ConnectionPool(config, err=>{
            // ... error checks

            // Query

            return pool.request() // or: new sql.Request(pool1)
                .query(sql, (err, result) => {
                    if(err){
                        reject(err)
                    }

                    if(result){
                        resolve(result);
                    }
                    //console.dir(result)
                })
        });
        pool.on('error', err => {
            reject(err);
        })

    });

}
module.exports = getQuery;